import React from 'react'
import ReactEcharts from 'echarts-for-react'

const Radanotrans = ({ datas }) => {
  const getVirtulData = () => {
    // year = year || '2019'
    let data = []
    Object.keys(datas).map(key => {
      let value = parseInt(datas[key])
      data.push({ value: value, name: key })
    })
    return data
  }

  const option = {
    tooltip: {
      trigger: 'item',
      formatter: '{a} <br/>{b} : {c} ({d}%)',
    },
    legend: {
      x: 'center',
      y: 'top',
      // orient: "vertical"
    },
    // toolbox: {
    //   show: true,
    //   feature: {
    //     mark: { show: true },
    //     dataView: { show: true, readOnly: false },
    //     magicType: {
    //       show: true,
    //       type: ['pie', 'funnel']
    //     },
    //     restore: { show: true },
    //     saveAsImage: { show: true }
    //   }
    // },
    calculable: true,
    series: [
      {
        name: '项目内设备上报次数',
        type: 'pie',
        radius: [10, 90],
        center: ['50%', '50%'],
        roseType: 'radius',
        label: {
          normal: {
            show: false,
          },
          emphasis: {
            show: true,
          },
        },
        lableLine: {
          length: '10px',
          length2: '10px',
          normal: {
            show: false,
          },
          emphasis: {
            show: true,
          },
        },
        data: getVirtulData(),
      },
    ],
  }

  return (
    <ReactEcharts
      option={option}
      // style={{ height: "240px" }}
      className="react_for_echarts"
    />
  )
}

export default Radanotrans
